package io.github.annyylxyms.gyncache.command;

import io.github.annyylxyms.gyncache.core.Command;
import io.github.annyylxyms.gyncache.core.GynCache;
import io.github.annyylxyms.gyncache.core.Reply;

/**
 *
 * @author Anny
 * @date 2025/1/15 20:48
 */
public class ZscoreCommand implements Command {
    @Override
    public String name() {
        return "ZSCORE";
    }

    /**
     * 取一个元素的分数
     * @param cache
     * @param args
     * @return
     */
    @Override
    public Reply<?> exec(GynCache cache, String[] args) {
        String key = getKey(args);
        String val = getVal(args);
        //可能返回空类型，需要判断
        Double zscore = cache.zscore(key, val);
        return Reply.string(zscore == null ? null : zscore.toString());
    }
}
